import { Raw, markRaw } from 'vue'

/**
 * @description  操作地图呼吸点 (暂时不用)  此方法目前还不完善
 * @author   邓清波
 *
 * ***/

export default function useBreath() {
  // 容器实例
  const locaContainerInstance = new Loca.Container({
    map: window._map
  })
  let scatterInstance = null

  /**
   * @desc 创建呼吸点
   * **/
  function createBreath(options) {
    //   动画图层实例
    scatterInstance = new Loca.ScatterLayer({
      loca: markRaw(locaContainerInstance),
      zIndex: 113,
      opacity: 1,
      visible: true,
      zooms: [7, 19]
    })
    // 呼吸点位置信息
    const geoLevelF = new Loca.GeoJSONSource({
      data: {
        type: 'FeatureCollection',
        features: [
          {
            type: 'Feature',
            properties: {},
            geometry: {
              type: 'Point',
              coordinates: [119.17044250793458, 32.35018109315219]
            }
          }
        ]
      }
    })
    scatterInstance.setSource(geoLevelF)
    // 红色呼吸点
    scatterInstance.setStyle({
      unit: 'meter',
      size: [5000, 5000],
      borderWidth: 0,
      texture: 'https://a.amap.com/Loca/static/loca-v2/demos/images/breath_red.png',
      duration: 500,
      animate: true
    })

    locaContainerInstance.animate.start()
  }

  /**
   * 销毁呼吸点
   *
   * **/
  function destroyBreath() {
    if (scatterInstance) {
      scatterInstance.destroy()
      scatterInstance = null
    }
  }
}
